#ifndef TCPSOCKET_H
#define TCPSOCKET_H

#include <QObject>
#include <QQmlEngine>
#include <QTcpSocket>
#include <QStandardItemModel>
#include <QJsonObject>


class MyTcpSocket : public QObject
{
    Q_OBJECT
    QML_ELEMENT
public:
    explicit MyTcpSocket(QObject *parent = nullptr);
    ~MyTcpSocket();

    Q_INVOKABLE bool sendMsg(const QJsonObject &qmlJsonObject);
    Q_INVOKABLE bool updateDataFromSocket();
    Q_PROPERTY(QVariantList dataFromSocket READ dataFromSocket NOTIFY dataFromSocketChanged);
    QVariantList dataFromSocket() const { return m_dataFromSocket; };

    // 在类成员中声明
    //    QStandardItemModel *model;

private:
    QTcpSocket *socket;
    QString ServerIP;
    quint16 PORT;
    QString HostIP;

private slots:
    void slotReadyRead();
signals:
    void dataFromSocketChanged();

private:
    QVariantList m_dataFromSocket;
    QString getLocalIPAddress();
};

#endif // TCPSOCKET_H
